<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title th:text="${task.taskId != null} ? '编辑任务' : '发布任务'">任务管理</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <div th:replace="~{fragments/header :: header}"></div>
    
    <div class="container mt-4">
        <h2 th:text="${task.taskId != null} ? '编辑任务' : '发布新任务'">任务表单</h2>
        
        <form th:action="@{/employer/tasks/{taskId}(taskId=${task.taskId})}" th:method="post" th:if="${task.taskId != null}"
              th:object="${task}">
            <input type="hidden" th:field="*{taskId}" />
            <!-- 保留原始发布时间 -->
            <input type="hidden" th:field="*{publishDate}" />
            
            <div class="mb-3">
                <label for="title" class="form-label">任务标题</label>
                <input type="text" class="form-control" id="title" th:field="*{title}" required>
                <div class="text-danger" th:if="${#fields.hasErrors('title')}" th:errors="*{title}"></div>
            </div>
            
            <div class="mb-3">
                <label for="description" class="form-label">任务描述</label>
                <textarea class="form-control" id="description" th:field="*{description}" rows="5" required></textarea>
                <div class="text-danger" th:if="${#fields.hasErrors('description')}" th:errors="*{description}"></div>
            </div>
            
            <div class="mb-3">
                <label for="budget" class="form-label">任务预算</label>
                <input type="number" class="form-control" id="budget" th:field="*{budget}" step="0.01" min="0" required>
                <div class="text-danger" th:if="${#fields.hasErrors('budget')}" th:errors="*{budget}"></div>
            </div>
            
            <div class="mb-3">
                <label for="taskStatus" class="form-label">任务状态</label>
                <select class="form-control" id="taskStatus" th:field="*{taskStatus}">
                    <option value="open">待承接</option>
                    <option value="in_progress">进行中</option>
                    <option value="completed">已完成</option>
                    <option value="closed">已关闭</option>
                </select>
            </div>
            
            <div class="mb-3">
                <label for="publishDate" class="form-label">发布时间</label>
                <input type="text" class="form-control" id="publishDate" th:field="*{publishDate}" disabled>
            </div>
            
            <button type="submit" class="btn btn-primary">更新任务</button>
            <a th:href="@{/employer/tasks}" class="btn btn-secondary">返回</a>
        </form>
        
        <form th:action="@{/employer/tasks}" th:method="post" th:if="${task.taskId == null}" th:object="${task}">
            <div class="mb-3">
                <label for="title" class="form-label">任务标题</label>
                <input type="text" class="form-control" id="title" th:field="*{title}" required>
                <div class="text-danger" th:if="${#fields.hasErrors('title')}" th:errors="*{title}"></div>
            </div>
            
            <div class="mb-3">
                <label for="description" class="form-label">任务描述</label>
                <textarea class="form-control" id="description" th:field="*{description}" rows="5" required></textarea>
                <div class="text-danger" th:if="${#fields.hasErrors('description')}" th:errors="*{description}"></div>
            </div>
            
            <div class="mb-3">
                <label for="budget" class="form-label">任务预算</label>
                <input type="number" class="form-control" id="budget" th:field="*{budget}" step="0.01" min="0" required>
                <div class="text-danger" th:if="${#fields.hasErrors('budget')}" th:errors="*{budget}"></div>
            </div>
            
            <button type="submit" class="btn btn-primary">发布任务</button>
            <a th:href="@{/employer/tasks}" class="btn btn-secondary">取消</a>
        </form>
    </div>
    
    <div th:replace="~{fragments/footer :: footer}"></div>
</body>
</html>